package cn.trigram.validation.annotation.validator;

import cn.trigram.validation.annotation.OracleNumberCheck;
import java.math.BigDecimal;
import java.util.Objects;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * OracleNumber校验器
 *
 * @version 1.0.0
 * @date 2022/08/04 09:11:06
 * @since 1.0.0
 */
public class OracleNumberForIntegerValidator extends AbstractOracleNumberValidator implements ConstraintValidator<OracleNumberCheck, Integer> {

    @Override
    public void initialize(OracleNumberCheck oracleNumberCheck) {
        super.initialize(oracleNumberCheck);
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (Objects.isNull(value)) {
            // 空值放过
            return true;
        }
        final BigDecimal decimal = new BigDecimal(value);
        return super.isValid(context, decimal);
    }
}